<?php

declare(strict_types=1);

namespace App\Model\CommodityModel;

use App\Model\BaseModel\BaseCommodityModel;
use Hyperf\DbConnection\Db;
class SupplierCommodityTag extends BaseCommodityModel
{
    public $table = 'suppliercommoditytag_s2b';
    
    /**
     * 标签搜索
     * @param array $ids
     */
    public function getTagNameListBySupplierCommodityIDs( $ids = [] ) 
    {
        $list = $this
        ->from($this->table." as scb_tag")
        ->select([
            'scb_tag.SupplierCommodityID',
            Db::raw('CONCAT(t.ID,"") as ID'),
            't.Name',
        ])
        ->join("tag_s2b as t","t.ID","=","scb_tag.TagID")
        ->whereIn('scb_tag.SupplierCommodityID',$ids)
        ->get()
        ->toArray();
        $listMap = [];
        foreach ($list as $item ) {
            $listMap[$item['SupplierCommodityID']][$item['ID']] = [
                'id'    => $item['ID'],
                'name'    => $item['Name'],
            ];
            unset($item);
        }
        
        foreach ($listMap as & $item ) {
            rsort($item);
        }
        
        return $listMap;
    }
}
